// 绘制图片列表的样式
<template>
  <!-- 这是顶部滑动条 -->
  <div>
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a
            :class="['mui-control-item',item.id==0?'mui-active':'']"
            href="#item2mobile"
            v-for="item in cates"
            :key="item.id"
          @click="getPhotolist(item.id)">{{item.title}}</a>
        </div>
      </div>
    </div>
    <!-- 图片列表区域 -->
    <ul>
      <router-link tag="li" v-for="item in list" :key="item.id" :to="'/home/photoinfo'+item.id">
        <img v-lazy="item.img_url" />
      </router-link>
    </ul>
  </div>
</template>
<script>
import mui from "../../lib/MUI/js/mui.min.js";

export default {
  data() {
    return {
      cates: [],
      list:[]
    };
  },
  mounted() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005
    });
  },
  created() {
    this.getAllCategory();
    this.getPhotolist(0);
  },
  methods: {
    getAllCategory() {
      this.$http.get("api/getimgcategory").then(result => {
        if (result.body.status === 0) {
          result.body.message.unshift({
            title: "全部",
            id: "0"
          });
          this.cates = result.body.message;
        }
      });
    },
    getPhotolist(cateID){
      // 根据分类Id,获取图片的列表
      this.$http.get("api/getimages/"+cateID).then(result=>{
        if(result.body.status===0){
          this.list=result.body.message;
        }
      })

    }
  }
};
</script>
<style lang="less" scoped>
img[lazy="loading"] {
  width: 40px;
  height: 300px;
  margin: auto;
}
ul{background:#eee;}
</style>